#include <stdio.h>
#include <mpi.h>

int** map_flow(struct DCmonitor *monitor) {

	int nfiles = monitor->nr_files, mhosts = monitor->nr_hosts;
	int V = nfiles + mhosts + 2;
	
	int **graph;
	graph = (int **)malloc(sizeof(int *) * V);
	for (int i = 0; i< V; i++)
		graph[i] = (int *)malloc(V * sizeof(int));

	for(int i =0; i < V; i++)
	{	
		for(int j =0; j < V;j++)
		{
			graph[i][j] = 0;
		}
	}

	for (int i = 1; i <= nfiles; i++)
		graph[0][i] = 1;

	int hindex;
	for (int f = 0; f < nfiles; f++){
		for (int h = 0; h < monitor->rep; h++){
			hindex = monitor->map[f][h];
			graph[f + 1][nfiles + 1 + hindex] = 1;
		}
	}

	for (int j = nfiles + 1; j <= nfiles + mhosts;j++)
		graph[j][V - 1] = (nfiles) / (mhosts);

	return graph;
}

void flow_showgraph(int** graph, int V)
{
	printf("show graph!\n");
	for (int u = 0; u < V; u++)
	{
		for (int v = 0; v < V; v++)
		{
			printf("%d, ", graph[u][v]);
		}
		printf("\n");
	}
}
